const path = require('path');
const addStyleResource = (rule) => {
  rule.use('style-resource')
    .loader('style-resources-loader')
    .options({
      patterns: [
        path.resolve(__dirname, './src/assets/scss/base/_index.scss'),
      ],
    });
};

module.exports = {
  lintOnSave: false,
  chainWebpack: (config) => {
    // 清除默认的图片loader
    const svgRule = config.module.rule('images');
    svgRule.uses.clear();
    // 统一引入公共scss变量
    const types = [
      'vue-modules',
       'vue', 
      'normal-modules',
       'normal',
       'scss'
    ];
    types.forEach(type => addStyleResource(config.module.rule('scss').oneOf(type)));
    // eslint配置
    // config.module.rule('eslint').use('eslint-loader').tap(options => {
    //   console.log(options,'---');
    //   options.emitError = true;
    //   options.emitWarning = true;
    //   options.fix = true;
    //   options.failOnWarning = true;
    //   options.failOnError = true;
    //   options.eslintPath = '@vue/eslint';
    // });
  },
  configureWebpack: {
    module: {
      rules: [
        {
          test: /\.png/,
          use: [
            'file-loader?name=i/[hash].[ext]',
          ],
        },
      ],
    },
    resolve: {
      modules: [
        'node_modules', path.resolve(__dirname, 'src/assets/scss'),
      ],
      alias: {
        '@': path.resolve(__dirname, 'src'),
      },
    },
    devtool: 'sourcemap',
  },
  devServer: {
    // disableHostCheck: true,
    // https: true,
    clientLogLevel: 'warning',
    historyApiFallback: true,
    hot: true,
    compress: true,
    host: 'localhost',
    port: 8080,
   // host: process.env.HOST || config.dev.host,
    quiet: true, // necessary for FriendlyErrorsPlugin
    overlay: {
        warning: true,
        errors: true
    },
    disableHostCheck: true,
    proxy: {
      "/test": {
          target: "http://119.23.243.5:8080/",
          changeOrigin: true,
          secure: true, // 接受 运行在 https 上的服务
      }
  }
  },
};
